package com.week.tiny_video.service.impl;

import com.week.tiny_video.dao.CategoryDao;
import com.week.tiny_video.pojo.Category;
import com.week.tiny_video.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;


import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryDao categoryDao;
    @Override
    public void add(Category category) {
        categoryDao.save(category);
    }

    @Override
    public Category get(int id) {
        return categoryDao.findById(id).orElse(null);
    }

    @Override
    public List<Category> list() {
        Sort sort = new Sort(Sort.Direction.ASC, "id");
        return categoryDao.findAll(sort);
    }

    @Override
    public Category getByName(String name) {
        return null;
    }

    @Override
    public void update(Category category) {
        categoryDao.save(category);
    }

    @Override
    public void delete(int id) {
        categoryDao.deleteById(id);
    }
}
